import 'package:app/shared/constants/common.dart';
import 'package:flutter/material.dart';
import 'package:flutter_swiper_null_safety/flutter_swiper_null_safety.dart';

// ignore: must_be_immutable
class DisTitleCom extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(
          top: sDefaultMarginPadding * 4, bottom: sDefaultMarginPadding * 3),
      height: 190,
      child: Swiper(
        autoplay: true,
        itemBuilder: (BuildContext context, int index) {
          return ItemSwipe();
        },
        itemCount: 3,
        pagination: SwiperPagination(
            builder: DotSwiperPaginationBuilder(
                color: Colors.grey.shade300, activeColor: Colors.black)),
      ),
    );
  }
}

class ItemSwipe extends StatelessWidget {
  ItemSwipe({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    List listData = [
      {
        "title": "热门话题",
        "author": "30",
        "image": "https://www.itying.com/images/flutter/1.png"
      },
      {
        "title": "旺旺插画设计",
        "author": "内容2",
        "image": "https://www.itying.com/images/flutter/2.png"
      },
      {
        "title": "随手拍",
        "author": "内容3",
        "image": "https://www.itying.com/images/flutter/3.png"
      },
      {
        "title": "遇见好风景",
        "author": "内容4",
        "image": "https://www.itying.com/images/flutter/4.png"
      },
    ];

    List<Widget> Boxs() => List.generate(
        listData.length,
        (index) => Container(
              width: MediaQuery.of(context).size.width / 2 -
                  3 * sDefaultMarginPadding -
                  2,
              child: Row(children: [
                Container(
                  width: 64,
                  height: 64,
                  decoration: BoxDecoration(
                      borderRadius:
                          BorderRadius.circular(sDefaultMarginPadding),
                      image: DecorationImage(
                          image: NetworkImage(listData[index]["image"]),
                          fit: BoxFit.cover)),
                ),
                Padding(
                  padding: EdgeInsets.only(left: sDefaultMarginPadding * 2),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text("#${listData[index]["title"]}",
                          style: TextStyle(
                              color: sTextColor,
                              fontWeight: FontWeight.bold,
                              fontSize: 13)),
                      SizedBox(
                        height: 8,
                      ),
                      Text("${index}动态",
                          style: TextStyle(color: sTextColorDes)),
                    ],
                  ),
                )
              ]),
            ));

    return Wrap(
      spacing: 2,
      runSpacing: 16,
      children: Boxs(),
    );
  }
}
